import os
import sys
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *

class ExportWindow(QWidget):
    path_Signal=pyqtSignal(str)
    def __init__(self):
        super(ExportWindow,self).__init__()
        self.setWindowTitle('输出路径')
        self.mainLayout = QHBoxLayout()
        self.mainLayout.setSpacing(20)
        self.btn_style='''QPushButton{color:black}
                                  QPushButton:hover{color:red}
                                  QPushButton{background-color:#FFDEAD}
                                  QPushButton{border:2px}
                                  QPushButton{border-radius:3px}
                                  QPushButton{padding:1px 1px}'''
        self.path_label = QLabel('输出路径:')
        self.path_edit = QLineEdit()
        self.path_btn = QPushButton('...')
        self.path_btn.setStyleSheet(self.btn_style)
        self.path_btn.setMaximumWidth(25)
        self.path_btn.clicked.connect(self.__chooseDir)
        self.OK_btn = QPushButton('导出')
        self.OK_btn.setShortcut(Qt.Key_Enter)
        self.OK_btn.setStyleSheet(self.btn_style)
        self.OK_btn.clicked.connect(self.__setPath)
        self.OK_btn.setMaximumWidth(40)
        self.NO_btn = QPushButton('取消')
        self.NO_btn.setStyleSheet(self.btn_style)
        self.NO_btn.clicked.connect(self.__close)
        self.NO_btn.setMaximumWidth(40)
        self.mainLayout.addWidget(self.path_label)
        self.mainLayout.addWidget(self.path_edit)
        self.mainLayout.addWidget(self.path_btn)
        self.mainLayout.addWidget(self.OK_btn)
        self.mainLayout.addWidget(self.NO_btn)
        self.setLayout(self.mainLayout)

    def __chooseDir(self):
        # dir = QFileDialog.getExistingDirectory(self, '选择目录')
        fileName = QFileDialog.getSaveFileName(None,'输出文件','','Excel files(*.xlsx , *.xls)')
        # print(fileName[0])
        self.path_edit.setText(fileName[0])

    def __setPath(self):
        dir = self.path_edit.text()
        self.path_Signal.emit(dir)
        self.close()

    def __close(self):
        self.close()




if __name__ == '__main__':
    app=QApplication(sys.argv)
    ex=ExportWindow()
    ex.show()
    sys.exit(app.exec_())